package commons.conf.base;

import org.apache.commons.lang.builder.ToStringBuilder;

import commons.conf.ResourceDomainField;

/**
 * 
 * @author jkyang
 *
 */
public class BaseResourceDomainField implements ResourceDomainField {

	private String id; //in XML
	private int length; //in XML
	private int scale;
	private String name;//in XML
	private String type;//in XML
	private boolean insert; // ?
	private boolean notNull;//in XML
	private boolean update; // ?

	private boolean unique;//in XML

	private boolean foreign;//in XML

	private String foreignRef;//in XML
	
	private String javaType;
	

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

	public String getForeignRef() {
		return foreignRef;
	}

	public void setForeignRef(String foreignRef) {
		this.foreignRef = foreignRef;
	}

	public String getForeignRefDomainFieldName() {
		return foreignRef.split("\\.")[1];
	}

	public String getForeignRefDomainName() {
		return foreignRef.split("\\.")[0];
	}

	public String getId() {
		return id;
	}

	public int getLength() {
		return length;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public boolean isForeign() {
		return foreign;
	}

	public boolean isInsert() {
		return insert;
	}

	public boolean isNotNull() {
		return notNull;
	}

	public boolean isUnique() {
		return unique;
	}

	public boolean isUpdate() {
		return update;
	}

	public void setForeign(boolean foreign) {
		this.foreign = foreign;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setInsert(boolean insert) {
		this.insert = insert;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNotNull(boolean notNull) {
		this.notNull = notNull;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setUnique(boolean unique) {
		this.unique = unique;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}
	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	public String getJavaType() {
		return javaType; 
	}

	public String getJavaTypePkg() {
		return javaType.substring(0, javaType.lastIndexOf("."));
	}

	public String getJavaTypeSimple() {
		return javaType.substring(javaType.lastIndexOf(".") + 1, javaType.length());
	}

	public boolean isPk() {
		return false;
	}
}
